<#assign title ="角色授权">
<#include "/include/layout.ftl">
<#macro css>
<link rel="stylesheet" type="text/css" href="${contextPath}/js/zTree/css/zTreeStyle/zTreeStyle.css" /> 
</#macro>
<#macro js>
</#macro>
<#macro body>
<#import "/include/select.ftl" as items>
	<section class="content-header">
      <h1>
        ${title}
      	<a class="btn btn-default pull-right back" href="javascript:;"><i class="fa fa-reply"></i> 返回</a>
		<a class="btn btn-info pull-right submit" ><i class="fa fa-save"></i> 确定</a>
      </h1>
    </section>
    <section class="content">
 		<div class="box box-info">
 			<div class="row">
 				<div class="col-sm-10">
			        <div class="box-header with-border">
			        	菜单信息
			        </div>
			        <form action="${contextPath}/sys/role/save" method="post" id="documentForm" class="form-horizontal">
			          <input type="hidden" name="id" value="${data.id}" />
		              <div class="box-body">
		              	<div class="form-group">
		              		<div class="col-sm-4"></div>
		              		<div class="col-sm-6">
		                  		<ul id="treeMenu" class="ztree"></ul>
		                  	</div>
		                </div>
		              </div>
		            </form>
		         </div>
            </div>
        </div>
    </section>
    <script type="text/javascript" src="${contextPath}/js/zTree/js/jquery.ztree.core.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="${contextPath}/js/zTree/js/jquery.ztree.excheck.min.js" charset="utf-8"></script>
	<script type="text/javascript">
		var setting = {
			check: {
				enable: true,
				chkDisabledInherit: true
			},
			view: {
				showIcon: false
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};
		$.fn.zTree.init($("#treeMenu"), setting, ${nodelist}); //树
		
		$(function(){
			$(".submit").click(function(){
				  var treeObj=$.fn.zTree.getZTreeObj("treeMenu");
		     	  var nodes=treeObj.getCheckedNodes(true);
		     	  var ids=[];
			      for(var i=0;i<nodes.length;i++){
			           ids[i] = nodes[i].id; 
			      }
	              $.post("${contextPath}/sys/role/menu_grant_save",{"roleid":"${roleid}","ids":ids},showResponse);
			})
		})
		
		
		//ajax 返回
		function showResponse(responseText, statusText) {
			var code = responseText.code;
			var msg = responseText.msg;
			if (code == "1") {
				  layer.alert(msg,{icon: 1}, function(index){
					  location.href="${contextPath}/sys/role/index.html";
				 	  layer.close(index);
				});  
			} else {
				layer.msg(msg, {icon: 2});
			}
		}	
		
	</script>
</#macro>